﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace VirtualBank
{   //信用账户
    internal class CreditAccount : Account
    {
        public double CreditLimit {  get;private set; }//信用额度

        public CreditAccount(int id, string ownerName, string password,double initialBalance, double creditLimit)
          : base(id, ownerName, password,initialBalance)
        {
            CreditLimit = creditLimit;
        }

        public CreditAccount() { }

        public override void withdraw(double amount)
        {
            //当索取金额在可用额度(信用额度+余额)之内           
            if (amount > 0 && amount <= (CreditLimit+Balance))
            {   
                //当余额不足时
                if (amount > Balance)
                {
                    Balance = 0;
                    CreditLimit -=(amount-Balance);
                }
                else
                {
                    Balance -= amount;
                }
            }
            else
                throw new IllegalException("不合法的取款金额");
        }
    }



}
